package com.temp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.temp.dto.SearchPaymentDTO;
import com.temp.entity.PaymentOrder;
import com.temp.mapper.PaymentOrderMapper;
import com.temp.service.PaymentOrderService;
import com.temp.vo.CustomPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Service
public class PaymentOrderServiceImpl extends ServiceImpl<PaymentOrderMapper, PaymentOrder> implements PaymentOrderService {

    @Autowired
    private PaymentOrderMapper paymentOrderMapper;

    @Override
    public CustomPageVO<PaymentOrder> queryAllPaymentOrder(SearchPaymentDTO paymentDTO) {
        CustomPageVO<PaymentOrder> customPageVO = new CustomPageVO<>();
        Integer count = Optional.ofNullable(paymentOrderMapper.countAllPaymentViews(paymentDTO)).orElse(0);
        customPageVO.setTotal(count);
        if(count < 1) {
            customPageVO.setDataList(Collections.emptyList());
            return customPageVO;
        }

        List<PaymentOrder> permissions = paymentOrderMapper.findAllPaymentViews(paymentDTO);
        customPageVO.setDataList(permissions);
        return customPageVO;
    }
}
